package com.example.project.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.entity.Watcher;
import com.example.project.enums.BusinessType;
import com.example.project.service.WatcherService;
import com.example.project.utils.poi.ExcelUtil;

/**
 * 用户关注Controller
 * 
 * @author ruoyi
 * @date 2025-11-06
 */
@Controller
@RequestMapping("/project/watcher")
public class WatcherController extends BaseController {

	private String prefix = "project/watcher";

	@Autowired
	private WatcherService watcherService;

	@RequiresPermissions("project:watcher:view")
	@GetMapping()
	public String watcher() {
		return prefix + "/watcher";
	}

	/**
	 * 查询用户关注列表
	 */
	@RequiresPermissions("project:watcher:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Watcher watcher) {
		startPage();
		List<Watcher> list = watcherService.selectWatcherList(watcher);
		return getDataTable(list);
	}

	/**
	 * 导出用户关注列表
	 */
	@RequiresPermissions("project:watcher:export")
	@Log(title = "用户关注", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Watcher watcher) {
		List<Watcher> list = watcherService.selectWatcherList(watcher);
		ExcelUtil<Watcher> util = new ExcelUtil<Watcher>(Watcher.class);
		return util.exportExcel(list, "用户关注数据");
	}

	/**
	 * 新增用户关注
	 */
	@RequiresPermissions("project:watcher:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存用户关注
	 */
	@RequiresPermissions("project:watcher:add")
	@Log(title = "用户关注", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Watcher watcher) {
		return toAjax(watcherService.insertWatcher(watcher));
	}

	/**
	 * 修改用户关注
	 */
	@RequiresPermissions("project:watcher:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		Watcher watcher = watcherService.selectWatcherById(id);
		mmap.put("watcher", watcher);
		return prefix + "/edit";
	}

	/**
	 * 修改保存用户关注
	 */
	@RequiresPermissions("project:watcher:edit")
	@Log(title = "用户关注", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Watcher watcher) {
		return toAjax(watcherService.updateWatcher(watcher));
	}

	/**
	 * 删除用户关注
	 */
	@RequiresPermissions("project:watcher:remove")
	@Log(title = "用户关注", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(watcherService.deleteWatcherByIds(ids));
	}
}
